/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Tela_Principal.java
 *
 * Created on 15/01/2011, 22:55:22
 */
package visao;

import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 *
 * @author Gelson
 */
public class Tela_Principal extends javax.swing.JFrame {

    //Variaveis
    String caminhoImagem = System.getProperty("user.dir") + "/src/Imagens/";
    final ImageIcon Windows = new ImageIcon(caminhoImagem + "windows.png");
    final ImageIcon Mac = new ImageIcon(caminhoImagem + "mac.png");
    final ImageIcon Linux = new ImageIcon(caminhoImagem + "linux.png");
    final ImageIcon Drive = new ImageIcon(caminhoImagem + "outros Drivers.png");
    final ImageIcon Pasta = new ImageIcon(caminhoImagem + "pastas.png");
    final ImageIcon Usb = new ImageIcon(caminhoImagem + "usb.png");
    final ImageIcon Arquivo = new ImageIcon(caminhoImagem + "outros Arquivos.png");
    final ImageIcon Cd = new ImageIcon(caminhoImagem + "cd.png");
    File meuComputador = new File("/");

    public Tela_Principal() {
        try {
            initComponents();
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            SwingUtilities.updateComponentTreeUI(this);
            Iniciar();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jtArvore = new javax.swing.JTree();
        jpArquivos = new javax.swing.JPanel();
        jpStatus = new javax.swing.JPanel();
        jpDrivers = new javax.swing.JPanel();
        jtfCaminho = new javax.swing.JTextField();
        jbVai = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane1.setViewportView(jtArvore);

        jpArquivos.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jpArquivosLayout = new javax.swing.GroupLayout(jpArquivos);
        jpArquivos.setLayout(jpArquivosLayout);
        jpArquivosLayout.setHorizontalGroup(
            jpArquivosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 749, Short.MAX_VALUE)
        );
        jpArquivosLayout.setVerticalGroup(
            jpArquivosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        jpStatus.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jpStatusLayout = new javax.swing.GroupLayout(jpStatus);
        jpStatus.setLayout(jpStatusLayout);
        jpStatusLayout.setHorizontalGroup(
            jpStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 872, Short.MAX_VALUE)
        );
        jpStatusLayout.setVerticalGroup(
            jpStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 55, Short.MAX_VALUE)
        );

        jtfCaminho.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jbVai.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbVai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/seta.png"))); // NOI18N
        jbVai.setBorderPainted(false);
        jbVai.setContentAreaFilled(false);
        jbVai.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbVai.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbVai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbVaiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpArquivos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addComponent(jtfCaminho, javax.swing.GroupLayout.PREFERRED_SIZE, 822, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbVai, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jpDrivers, javax.swing.GroupLayout.DEFAULT_SIZE, 876, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpDrivers, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jbVai, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCaminho, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
                    .addComponent(jpArquivos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbVaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbVaiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbVaiActionPerformed

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Tela_Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbVai;
    private javax.swing.JPanel jpArquivos;
    private javax.swing.JPanel jpDrivers;
    private javax.swing.JPanel jpStatus;
    private javax.swing.JTree jtArvore;
    private javax.swing.JTextField jtfCaminho;
    // End of variables declaration//GEN-END:variables

    public ImageIcon getSO() {
        ImageIcon img;
        String os = System.getProperty("os.name").toLowerCase();

        if (os.indexOf("win") >= 0) { //Windows
            img = Windows;
        } else if (os.indexOf("mac") >= 0) { //Mac
            img = Mac;
        } else { //Linux
            img = Linux;
        }

        return img;
    }

    public void Iniciar() {

        jtfCaminho = new JTextField();


        if (meuComputador.isDirectory()) {
            File[] listaUnidades = meuComputador.listRoots();

            for (final File file : listaUnidades) {
                JButton local = new JButton(file.getPath());


                if ((local.getText().equals("C:\\")) || (local.getText().equals("/")) || (local.getText().equals("root"))) {
                    local.setIcon(getSO());
                } else if (local.getText().equals("F:\\")) {
                    local.setIcon(Usb);
                } else if (local.getText().equals("D:\\")) {
                    local.setIcon(Cd);
                } else {
                    local.setIcon(Drive);
                }


                local.setHorizontalTextPosition(4);
                local.setVerticalTextPosition(0);
                jpDrivers.add(local);


            }

        }


    }
}
